package org.datascooter.test.example;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ChildTrade extends Trade {

	private static final long serialVersionUID = -7955079376770352199L;
	String benefit;

	public ChildTrade() {
	}

	public ChildTrade(Trade trade, String benefit) {
		super(trade.getName(), trade.getGoods(), trade.getPrice(), trade.getStart(), trade.getStop(), trade.getUserId());
		type = 1;
		this.benefit = benefit;
	}

	public ChildTrade(String name, String goods, Long price, Date start, Date stop, String userId, Integer type, String benefit) {
		super(name, goods, price, start, stop, userId);
		type = 1;
		this.benefit = benefit;
	}

	@Override
	public String toString() {
		return name + " - " + goods + " - " + price + " -benefit:  " + benefit;
	}

	@Override
	public Object[] flush() {
		return new Object[] {
				getId(), name, type, goods, price, start, stop, userId, benefit
		};
	}

	@Override
	public void restore(Object[] fields) throws Exception {
		id = fields[0] + "";
		name = fields[1] + "";
		type = new Integer(fields[2] + "");
		goods = fields[3] + "";
		price = new Long(fields[4] + "");
		start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(fields[5] + "");
		stop = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(fields[6] + "");
		userId = fields[7] + "";
		benefit = fields[8] + "";
	}

	public String getBenefit() {
		return benefit;
	}

	public void setBenefit(String benefit) {
		this.benefit = benefit;
	}
}
